/*
 * Helstius--Basic chemistry application
 * This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 * Copyright 2012 Jaked122
 */
package org.helstius.Gui;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
import java.util.TreeMap;

import javax.swing.JFrame;
import javax.swing.JPanel;

import org.helstius.util.Utility;

/**
 * Old bar chart with obnoxious features that don't <i>quite</i> work.
 * 
 * @author Jaked122
 * @deprecated
 */

public class BarChart extends JPanel {
	public void setpercentages(int[] particle) {
		particles = particle;
		Random e = new Random();
		cowers = new Color[particles.length];
		for (int i = 0; i < particles.length; i++) {
			cowers[i] = new Color(e.nextInt(255), e.nextInt(255),
					e.nextInt(255));
		}
		repaint();
	}

	Color[] cowers;

	boolean hasnames = false;
	private String[] names;
	private int[] particles;

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		if (particles != null) {
			int heift = getWidth() / Utility.max(particles);
			int vstep = getHeight() / particles.length;
			for (int y = 0; y < particles.length; y++) {
				g.setColor(cowers[y]);
				int x = 0;
				int z = vstep * y;

				g.fillRect(x, z, particles[y] * heift, vstep);
				g.setColor(Color.black);
				if (!hasnames)
					g.drawString(Integer.toString(particles[y]), x, z >= 0 ? z
							: vstep / 2);
			}
		}
	}

	public void setpercentages(TreeMap<String, Integer> cd) {
		Integer[] q = cd.values().toArray(new Integer[0]);
		setpercentages(q);
		hasnames = true;
	}

	public void setpercentages(Integer[] integers) {
		int[] i = new int[integers.length];
		for (int a = 0; a < integers.length; a++) {
			i[a] = integers[a].intValue();
		}
		this.setpercentages(i);
		hasnames = false;

	}
}
